﻿using System;
using Gpf.Whs.YouTubeDownloader.AddIn.CommSrv;

namespace Gpf.Whs.YouTubeDownloader.AddIn
{
    public partial class Gadget : Microsoft.WindowsServerSolutions.Web.Gadget
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            topDownloadsRepeater.Visible = false;
            emptyMessageField.Visible = false;

            DownloadItemStatus[] statuses = null;

            try
            {
                using (var client = CommSrvHelper.GetClient())
                {
                    statuses = client.GetItemStatuses();
                }
            }
            catch (Exception ex)
            {
                emptyMessageField.Text = ex.ToString();
                emptyMessageField.Visible = true;
                return;
            }

            if (statuses == null || statuses.Length == 0)
            {
                emptyMessageField.Visible = true;
            }
            else
            {
                topDownloadsRepeater.DataSource = statuses;
                topDownloadsRepeater.DataBind();
                topDownloadsRepeater.Visible = true;
            }
        }
    }
}